<script setup lang="ts">
interface Props {
  icon: any
  count?: string | number
  tip?: string
  countColor?: string
  unit?: string
}

const props = withDefaults(defineProps<Props>(), {
  count: 0,
  tip: '标题',
  unit: '人',
})

const imgUrl = computed(() => new URL(`/src/assets/icons/student-${props.icon}.svg`, import.meta.url).href)
</script>

<template>
  <div class="stat-item">
    <div class="stat-item-icon">
      <img :src="imgUrl" alt="">
    </div>
    <div class="info">
      <div class="top">
        <span class="count" :style="`color:${props.countColor}`">{{ props.count }}</span>
        <span class="unit">{{ props.unit }}</span>
      </div>
      <div class="tip">
        {{ props.tip }}
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.stat-item {
  display: flex;
  align-items: center;
  &-icon {
    width: 40px;
    height: 40px;
    box-sizing: border-box;
    padding: 6px;
    border-radius: 4px;
    background: #f5f7fd;

    .img {
      width: 100%;
      height: 100%;
    }
  }

  .info {
    margin-left: 10px;

    .top {
      min-width: 110px;
      line-height: 1;
      .count {
        font-weight: bold;
        font-size: 16px;
        font-weight: 500;
        color: #1d2129;
      }

      .unit {
        font-size: 12px;
        font-weight: 400;
        color: #86909c;
      }
    }

    .tip {
      margin-top: 5px;
      font-size: 12px;
      font-weight: 400;
      color: #4e5969;
      line-height: 1;
    }
  }
}
</style>
